extends Line2D
class_name Trail

@export var player : Player
@export var trail_length := 25
@export var trail_duration := 1.0

@onready var trail_timer := %TrailTimer

var position_array : Array[Vector2] = []
var is_active := false

func _process(delta: float) -> void:
	if not is_active:
		return
	
	position_array.append(player.global_position)
	if position_array.size() > trail_length:
		position_array.pop_front()
	
	points = position_array

# 开始绘制轨迹
func start_trail() -> void:
	is_active = true
	clear_points()
	position_array.clear()
	trail_timer.start(trail_duration)


func _on_trail_timer_timeout() -> void:
	is_active = false
	clear_points()
	position_array.clear()
